﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace for7raid.vkConnector
{

    public static class Audio
    {
        public const string AudioGet = "audio.get";
        public const string AudioSearch = "audio.search";
        public const string AudioGetLyrics = "audio.getLyrics";
        public const string AudioAdd = "audio.add";
        public const string AudioDelete = "audio.delete";
        public const string AudioEdit = "audio.edit";
        public const string AudioGetAlbums = "audio.getAlbums";
        public const string AudioAddAlbum = "audio.addAlbum";
        public const string AudioMoveToAlbum = "audio.moveToAlbum";

        public static Request GetMyAudio()
        {
            return new Request(AudioGet);
        }

        public static Request GetByUserId(int Id)
        {
            return new Request(AudioGet).AddParam("uid", Id);

        }

        public static Request GetByGroupId(int Id)
        {
            return new Request(AudioGet).AddParam("gid", Id);
        }

        public static Request GetByIds(params string[] Id)
        {
            return new Request(AudioGet).AddParam("audios", Id.Aggregate((i, l) => i + "," + l));
        }

        public static Request Search(string Text)
        {
            return new Request(AudioSearch).AddParam("auto_complete",1).AddParam("q", Text).AddParam("count", 200);
        }

        public static Request Search(string Text, bool withLyrics)
        {
            return new Request(AudioSearch).AddParam("auto_complete", 1).AddParam("q", Text).AddParam("lyrics", withLyrics ? 1 : 0).AddParam("count", 200);
        }

        public static Request GetRandom()
        {
            return new Request(AudioSearch)
                .AddParam("offset", new Random().Next(1000))
                .AddParam("count", 200)
                .AddParam("q", (char)new Random().Next(65,122))
                //.AddParam("lyrics", 1)
                ;
        }

        public static Request GetLyrics(int Id)
        {
            return new Request(AudioGetLyrics).AddParam("lyrics_id", Id);
        }

        public static Request AddAudio(int id, int ownerId)
        {
            return new Request(AudioAdd)
                .AddParam("oid", ownerId)
                .AddParam("aid", id);
        }

        public static Request Delete(int Id, int ownerId)
        {
            return new Request(AudioDelete).AddParam("aid", Id).AddParam("oid", ownerId);
        }

        public static Request Edit(int Id, int ownerId, string Artist, string Title, string Text)
        {
            return new Request(AudioEdit)
                .AddParam("aid", Id)
                .AddParam("oid", ownerId)
                .AddParam("artist", Artist)
                .AddParam("title", Title)
                .AddParam("text", Text)
                .AddParam("no_search", 0);
        }

        public static Request GetAlbumsByUserId(int Id)
        {
            return new Request(AudioGetAlbums).AddParam("uid", Id);
        }

        public static Request GetAlbumsByGroupId(int Id)
        {
            return new Request(AudioGetAlbums).AddParam("gid", Id);
        }

        public static Request AddUserAlbum(string Name)
        {
            return new Request(AudioAddAlbum).AddParam("title", Name);
        }

        public static Request GetByIds(int AlbumId, params int[] Id)
        {
            return new Request(AudioMoveToAlbum)
                .AddParam("aids", Id.Select(i => i.ToString()).Aggregate((i, l) => i + "," + l))
                .AddParam("album_id", AlbumId);
        }
    }

}
